#include<bits/stdc++.h>
#define int long long
using namespace std;
namespace IO
{
	char buff[1<<21],*p1=buff,*p2=buff;
	char getch(){return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;}
	template<typename T>void read(T &x){char ch=getch();int fl=1;x=0;while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}x*=fl;}
	template<typename T>void read_s(T &x){x="";char ch=getch();while(ch<'a'||ch>'z')ch=getch();while(ch>='a'&&ch<='z'){x+=ch;ch=getch();}}
	template<typename T,typename ...Args>void read(T &x,Args& ...args){read(x);read(args...);}
	char obuf[1<<21],*p3=obuf;
	void putch(char ch) {if(p3-obuf<(1<<21))*p3++=ch;else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;}
	char ch[100];
	template<typename T>void write(T x) {if(!x)return putch('0');if(x<0)putch('-'),x*=-1;int top=0;while(x)ch[++top]=x%10+48,x/=10;while(top)putch(ch[top]),top--;}
	template<typename T,typename ...Args>void write(T x,Args ...args) {write(x);write(args...);}
	void put(string s){for(int i=0;i<s.size();i++)putch(s[i]);}
	void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
int n;
namespace Chtholly
{
	struct node
	{
		int l,r;
		bool operator<(const node &a)const{return l<a.l;}
	};
	set<node>odt;
	auto split(int p)
	{
		auto it=odt.lower_bound((node){p,0});
		if(it!=odt.end()&&it->l==p) return it;
		--it;
		if(it->r<p) return odt.end();
		int l=it->l,r=it->r;
		odt.erase(it);
		odt.insert((node){l,p-1});
		return odt.insert((node){p,r}).first;
	}
	int now;
	inline void assign(int l,int r)
	{
		if(!odt.size())
		{
			odt.insert((node){l,r});now+=r-l+1;
			return;
		}
		auto itr=split(r+1),itl=split(l);
		for(auto it=itl;it!=itr;it++) now-=it->r-it->l+1;
		odt.erase(itl,itr);
		odt.insert((node){l,r});now+=r-l+1;
	}
}using namespace Chtholly;
int m,sum[400005],s;
set<int>a;
int tmp[400005];
int cnt[400005];
int vis[400005];
signed main()
{
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	read(n);
	srand(time(NULL));
	for(int _=1;_<=n;_++)
	{
		read(tmp[_]);
		int x=tmp[_];
		if(a.find(x)!=a.end()) a.erase(x),--m;
		else a.insert(x),++m;
		++cnt[m];
	}
	int T=1.5e8;
	for(int i=1;i<=n;i++) vis[i]=min(cnt[i],T/40/i),T-=min(cnt[i],T/40/i)*40*i;
	a.clear();m=0;
	for(int _=1;_<=n;_++)
	{
		int x=tmp[_];
		if(a.find(x)!=a.end()) a.erase(x),--m,s-=x;
		else a.insert(x),++m,s+=x;
		if(vis[m])
		{
			now=0;odt.clear();
			auto it=a.begin();
			for(int i=1;i<=m;++it,i++) sum[i]=sum[i-1]+*it;
			for(int i=1;i<=m;i++) if(sum[i]<sum[m]-sum[m-i]) assign(sum[i],sum[m]-sum[m-i]-1);
			write(now);
			--vis[m];
		}
		else
		{
			if(a.size()<=1) write(0);
			else write(s-*a.begin()*2);
		}
		putch('\n');
	}
	flush();
	return 0;
}
